From 84ff1f21556688762372eac5891959859880ff58 Mon Sep 17 00:00:00 2001 From: "cl349@firebug.cl.cam.ac.uk" Date: Mon, 5 Sep 2005 19:43:04 +0000 Subject: [PATCH] Add @introduceDomain event-watch and replace consoled watch on /console. Signed-off-by: Christian Limpach --- tools/console/daemon/io.c | 7 +++---- tools/console/daemon/utils.c | 4 ++-- tools/xenstore/xenstored_core.c | 9 +++++++++ tools/xenstore/xenstored_core.h | 3 +++ tools/xenstore/xenstored_domain.c | 4 ++++ tools/xenstore/xenstored_watch.c | 18 ++++++++++++------ 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 885e291456..39956dccdf 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -212,12 +212,10 @@ int xs_gather(struct xs_handle *xs, const char *dir, ...) static int domain_create_ring(struct domain *dom) { - char *dompath, *path; + char *dompath; int err; - asprintf(&path, "/console/%d/domain", dom->domid); - dompath = xs_read(xs, path, NULL); - free(path); + dompath = xs_get_domain_path(xs, dom->domid); if (!dompath) return ENOENT; @@ -452,6 +450,7 @@ static void handle_xs(int fd) if (dom && (dom->evtchn_fd == -1 || dom->page == NULL)) domain_create_ring(dom); } + enum_domains(); xs_acknowledge_watch(xs, vec[1]); free(vec); diff --git a/tools/console/daemon/utils.c b/tools/console/daemon/utils.c index e29fc11ead..3e0400c6d1 100644 --- a/tools/console/daemon/utils.c +++ b/tools/console/daemon/utils.c @@ -233,8 +233,8 @@ bool xen_setup(void) goto out_close_data; } - if (!xs_watch(xs, "/console", "console")) { - dolog(LOG_ERR, "xenstore watch on /console fails."); + if (!xs_watch(xs, "@introduceDomain", "console")) { + dolog(LOG_ERR, "xenstore watch on @introduceDomain fails."); goto out_close_data; } diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index 4aef491ce1..3c7e6cc12d 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -828,6 +828,15 @@ bool check_node_perms(struct connection *conn, const char *node, return false; } +bool check_event_node(const char *node) +{ + if (!node || !strstarts(node, "@")) { + errno = EINVAL; + return false; + } + return true; +} + static void send_directory(struct connection *conn, const char *node) { char *path, *reply; diff --git a/tools/xenstore/xenstored_core.h b/tools/xenstore/xenstored_core.h index ce0f8fc792..fa407e9ae1 100644 --- a/tools/xenstore/xenstored_core.h +++ b/tools/xenstore/xenstored_core.h @@ -133,6 +133,9 @@ char *canonicalize(struct connection *conn, const char *node); bool check_node_perms(struct connection *conn, const char *node, enum xs_perm_type perm); +/* Check if node is an event node. */ +bool check_event_node(const char *node); + /* Path to this node outside transaction. */ char *node_dir_outside_transaction(const char *node); diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_domain.c index e98a347a85..2d6528105e 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -33,6 +33,7 @@ #include "talloc.h" #include "xenstored_core.h" #include "xenstored_domain.h" +#include "xenstored_watch.h" #include "xenstored_test.h" static int *xc_handle; @@ -308,6 +309,9 @@ void do_introduce(struct connection *conn, struct buffered_data *in) /* Now domain belongs to its connection. */ talloc_steal(domain->conn, domain); + + fire_watches(conn, "@introduceDomain", false); + send_ack(conn, XS_INTRODUCE); } diff --git a/tools/xenstore/xenstored_watch.c b/tools/xenstore/xenstored_watch.c index a2727e46e4..804a386868 100644 --- a/tools/xenstore/xenstored_watch.c +++ b/tools/xenstore/xenstored_watch.c @@ -103,7 +103,8 @@ static void add_event(struct connection *conn, /* Check read permission: no permission, no watch event. * If it doesn't exist, we need permission to read parent. */ - if (!check_node_perms(conn, node, XS_PERM_READ|XS_PERM_ENOENT_OK)) { + if (!check_node_perms(conn, node, XS_PERM_READ|XS_PERM_ENOENT_OK) && + !check_event_node(node)) { fprintf(stderr, "No permission for %s\n", node); return; } @@ -213,11 +214,16 @@ void do_watch(struct connection *conn, struct buffered_data *in) return; } - relative = !strstarts(vec[0], "/"); - vec[0] = canonicalize(conn, vec[0]); - if (!is_valid_nodename(vec[0])) { - send_error(conn, errno); - return; + if (strstarts(vec[0], "@")) { + relative = false; + /* check if valid event */ + } else { + relative = !strstarts(vec[0], "/"); + vec[0] = canonicalize(conn, vec[0]); + if (!is_valid_nodename(vec[0])) { + send_error(conn, errno); + return; + } } watch = talloc(conn, struct watch); -- 2.30.2